DV 18 - Detecting a CD-ROM
Title Banner


Technical Q&A's


DV 18 - Detecting a CD-ROM (1-July-95)


Q My application runs from the hard disk, but it requires a specific CD-ROM to be present on the system. I am concerned about the possibility that a user may have a hard-disk volume or a diskette with the same name as my CD-ROM. To check for this, my application searches for a specifically named locked volume that contains a certain file, and I'd like to simplify this process. What is the best way to determine if a mounted volume or SCSI address is a CD-ROM drive?

A Unfortunately, there is no foolproof way to determine whether a volume or a SCSI address on a Macintosh is a CD-ROM drive. However, there are some approaches you can take that work in most situations. These are some of the approaches you can take, along with a description of the situations in which they fail to work:

1. Inspect the drive-queue element for a mounted drive to determine which driver the dQRefNum points to. Then, inspect the driver's name. If the name is ".AppleCD", it's probably a CD-ROM drive.

This approach fails for non-Apple CD-ROM drives, since they have different driver names.

2. Inspect the drive's attributes in the four bytes preceding the drive-queue entry. If the drive is "locked in hardware" and is removable, it's probably a CD-ROM drive.

This approach can also fail in some configurations, since locked removable hard disks, optical media, and even diskettes can have the same attributes.

3. Issue a SCSI request directly to the drive.

This fails for some early CD-ROM drives (non-SCSI-2 compliant). Before SCSI-2, there was no CD-ROM device type defined, and some CD-ROM drives reported that they were hard disks. There is an additional complication introduced by SCSI Manager 4.3, and IDE CD-ROM drives require a completely different calling architecture.

4. Issue a ReadTOC() call to the driver, and inspect the result that is returned.

Although Control() with csCode 100 is a well-known CD-ROM driver call, there is nothing to prevent other drivers from using this call. Although few do, it is entirely possible for a non-CD-ROM driver to implement this call with different values in csParam, which could be disastrous.

The fourth approach is probably the most reliable. For each mounted drive, issue a ReadTOC call to the driver for that drive. If reasonable results are returned, you probably have a CD-ROM drive.
TechNote DV 22 on CD ROM Driver Calls

SCSI Manager 4.3 chapter in Inside Macintosh: Devices.

Developer Note on Quadra 630, IDE Manager.

Technical Support
Technical Q&As
Previous Question | Contents | Next Question

Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help